var rowid=null;
var pageSize = 10;
var flupTypeMap = {};
var flupStatusMap = {};
var sexCodeMap = {};
$(document).ready(function(){
	commonSet();
	//表格初始化
	initTable();
	//事件绑定
	eventBind();
});

function commonSet(){
	flupTypeMap=getTransParam('flupCon');
	flupStatusMap=getTransParam('flupCode');
	sexCodeMap=getTransParam('sexInfo');
}

function eventBind(){
	//带有分页信息的查询
	$("#queryBtn1").click(pageQuery).click();
	$("#queryUnBtn").click(pageQuery).click();
	$("#flupBtn").click(showAddFormDialog);
}

function initTable(){
	$('#unfinishTranTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			queryUn(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
		}
	});
	$('#finishTranTable').bootstrapTable({
		onPageChange: function (number, size) {
			pageSize = size;
			query(number, size);
		},
		onCheck:function (row) {
			rowid=row.id;
		}
	});
}

//带有分页信息的查询
function pageQuery(){
	queryUn(1, pageSize);
	query(1, pageSize);
};

//待随访
function queryUn(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#unfinishForm").collect()
	}
	$.getApiClient('/patient/listFlup').setQuery(queryCondition).post().done(function(data){
	    $('#unfinishTranTable').bootstrapTable('load', data.payload);
	});
};

//已随访
function query(pageNumber, pageSize){
	var queryCondition={
		pageNumber: pageNumber, 
		pageSize: pageSize,
		params:$("#finishForm").collect()
	}
	$.getApiClient('/flup/listFinsh').setQuery(queryCondition).post().done(function(data){
	    $('#finishTranTable').bootstrapTable('load', data.payload);
	});
};

//弹出申请内容页
function showAddFormDialog(){
	if(rowid==null){
		customAlertDialog("请选择患者后进行操作", '错误提示', null, null);
	}else{
		customRemoteUrlDialog('随访内容','/page/business/flup/flupForm?Id='+rowid,null);
	}
}

//操作列
function operateFormatter(value, row, index) {	
	var operates=[];
	operates.push('<a class="edit" href="javascript:void(0)" title="查看详细"><i class="fa fa-edit"></i>查看详细</a>');
	return operates.join('');
};


operateEvents = {
	'click .edit' : function(e, value, row, index) {
		showDetailFormDialog(row);
	}
};

//弹出查看详细页
function showDetailFormDialog(row){
	customRemoteUrlDialog('随访详情','/page/business/flup/flupView?Id='+row.id,null);
}

